#include "spawner.h"
#include "creep.h"
#include <iostream>

using namespace std;

void CSpawner::Spawn(int wx, int wy) {
    if (numcreeps-- > 0) {
        gamescene->obj()->push_back(std::unique_ptr<CObject>(new CCreep(wx,wy,gamescene,dhp)));
    } else {
        gamescene->NextWave();
    }
}

void CSpawner::Do() {
    if (getTicks() >= GetOpDelay()) {
        for (int i = 0; i < getTicks()/GetOpDelay(); i++) {
            Spawn(GetX(),GetY());
        }
        setTime(getTime() + GetOpDelay()*(getTicks()/GetOpDelay()));
    }
}

CSpawner::CSpawner(CScene *scene) {
    gamescene = scene;
    gamescene->assignSpawner(this);
    numcreeps = 10;
}

CSpawner::CSpawner(int tx, int ty, CScene *scene, int shp) {
    SetX(tx);
    SetY(ty);
    SetOpDelay(500);
    gamescene = scene;
    gamescene->assignSpawner(this);
    numcreeps = 10;
    paused = false;
    dhp = shp;
}

void CSpawner::Draw() {

}

void CSpawner::ReFill(int what, int shp) {
    dhp = shp;
    if (numcreeps < 0) numcreeps = 0;
    numcreeps += what;
}

void CSpawner::Pause() {
    paused = true;
}


